/*
 * sockets_cliente.c
 *
 *  Created on: 25/10/2011
 *      Author: utn_so
 */


#include <stdlib.h>
#include "raid.h"

#include "../Commons/sockets.h"
#include "structRaid.h"

#define CLIENT_PORT "3499"
#define RAID_PORT "3466"

int socket_client(int argc, char **argv) {
	int descriptor = socket(AF_INET, SOCK_STREAM, 0);
	struct sockaddr_in *local_address = malloc(sizeof(struct sockaddr_in));
	struct sockaddr_in *remote_address = malloc(sizeof(struct sockaddr_in));
	t_nipc paquete;

	{
		local_address ->sin_family = AF_INET;
		local_address ->sin_addr.s_addr = INADDR_ANY;
		local_address ->sin_port = htons(CLIENT_PORT);

		bind(descriptor, (struct sockaddr *) local_address, sizeof(struct sockaddr_in));
	}

	{
		remote_address ->sin_family = AF_INET;
		remote_address ->sin_addr.s_addr = inet_addr("127.0.0.1");
		remote_address ->sin_port = htons(RAID_PORT);
	}

	connect(descriptor, (struct sockaddr *) remote_address, sizeof(struct sockaddr_in));

	send(descriptor, paquete, sizeof(t_nipc), 0);

	close(descriptor);

	return EXIT_SUCCESS;

}
